package cn.edu.lcu.cs.javaprogramming.gui;

import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

public class MouseEventDemoForm {
    private JTextArea content;
    private JPanel rootPanel;
    private JMenuBar menuBar;

    public MouseEventDemoForm() {
        content.addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                // 获取鼠标的当前坐标
                int x = e.getX();
                int y = e.getY();
                // 更新文本区的内容，显示坐标
                String text = String.format("当前鼠标位置(%d, %d)", x, y);
                content.setText(text);
            }
        });
    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("MouseEventDemoForm");
        frame.setContentPane(new MouseEventDemoForm().rootPanel);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
